# @author: Samuel Taylor <samtaylor.uk@gmail.com>
# @package: winecellar
# @license: GNU GPLv3
#
# Copyright (C) 2010  Samuel Taylor <samtaylor.uk@gmail.com>
#----------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------

import os

__author__ = 'Samuel Taylor <samtaylor.uk@gmail.com>'
__version__ = 'pre0.1-dev'
__apphome__ = os.getenv("HOME") + "/.winecellar"
__configpath__ = __apphome__ + "/config.xml"
__logpath__ = __apphome__ + "/winecellar.log"
__bottlepath__ = __apphome__ + '/bottles/'
__cachePath__ = __apphome__ + '/cache/'
__repositoriesPath__ = __cachePath__ + 'repositories/'


# Where your project will look for your data (for instance, images and ui
# files). By default, this is ../data, relative your trunk layout
__dataPath__ = '../data'

class project_path_not_found(Exception):
    """Raised when we can't find the project directory."""


def get_data_file(*path_segments):
    """Get the full path to a data file.

    Returns the path to a file underneath the data directory (as defined by
    `get_data_path`). Equivalent to os.path.join(get_data_path(),
    *path_segments).
    """
    return os.path.join(get_data_path(), *path_segments)


def get_data_path():
    """Retrieve test data path

    This path is by default <test_lib_path>/../data/ in trunk
    and /usr/share/WineCellar in an installed version but this path
    is specified at installation time.
    """

    # Get pathname absolute or relative.
    path = os.path.join(
        os.path.dirname(__file__), __dataPath__)

    abs_data_path = os.path.abspath(path)
    if not os.path.exists(abs_data_path):
        raise project_path_not_found

    return abs_data_path
